package gdconf

import (
	"server_cluster/common/logger"
)

// 抽卡蛋池配置表

type GachaPoolConfig struct {
	Id     int32 `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 抽卡蛋池id
	PoolId int32 `csv:"Pool,omitempty"`                            // 蛋池id
	ItemId int32 `csv:"Item,omitempty"`                            // 道具id
	Weight int32 `csv:"Weight,omitempty"`                          // 权重
}

func (c *GachaPoolConfig) TableName() string {
	return "config_gacha_pool"
}

func (g *GameDataConfig) saveGachaPool() {
	saveTableToDb[GachaPoolConfig](g.Db, readTable[GachaPoolConfig](g.CsvPathPrefix+"CardPool.csv"))
}
func (g *GameDataConfig) loadGachaPoolConfig() {
	g.GameDataMaps.GachaPoolMap = make(map[int32]*GachaPoolConfig)
	for _, gachaPool := range loadTableFromDb[GachaPoolConfig](g.Db) {
		g.GameDataMaps.GachaPoolMap[gachaPool.Id] = gachaPool
	}
	logger.Info("GachaPoolConfig Count: %v", len(g.GameDataMaps.GachaPoolMap))
}

func (c *GachaPoolConfig) GetWeight() int32 {
	return c.Weight
}

func GetConfigGachaPoolMap() map[int32]*GachaPoolConfig { return CONF.GameDataMaps.GachaPoolMap }

func GetConfigGachaPoolByPoolId(poolId int32) []*GachaPoolConfig {
	ret := make([]*GachaPoolConfig, 0)
	for _, gachaPool := range CONF.GameDataMaps.GachaPoolMap {
		if gachaPool.PoolId != poolId {
			continue
		}
		ret = append(ret, gachaPool)
	}
	return ret
}
